﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using PolePositionMobileUtilityGeneral;
using PolePositionMobileUtilityEntity;

namespace PolePositionMobileUtilityApplication
{
    public partial class MapSectionDropDown : UserControl
    {
        List<Int32> _ValuesMap;
        List<Int32> _ValuesSection;

        public MapSectionDropDown()
        {
            InitializeComponent();
            _ValuesMap = new List<Int32>();
            _ValuesSection = new List<Int32>();
        }

        public void LoadDropDowns()
        {
            EMap m = new EMap();
            EMap[] mArray = m.GetAll();
            _ValuesMap = MobileUIHelper.FillDropdown(ddlMap, mArray, "Name", "Id", "[Map]");
            ESection[] eArray = ESection.GetAll();
            _ValuesSection = MobileUIHelper.FillDropdown(ddlSection, eArray, "Name", "Id", "[1 to 36]");
        }

        private void ddlMap_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlMap.SelectedIndex > 0)
            {
                
                ddlSection.Enabled = true;
                
            }
            else
            {
                ddlSection.Enabled = false;
            }
        }

        public int GetMapValue()
        {
            Int32 _returnValue = Int32.MinValue;
            if (ddlMap.SelectedIndex > 0 && ddlMap.Items.Count > 0)
            {
                _returnValue = _ValuesMap[ddlMap.SelectedIndex];
            }
            return _returnValue;
        }

        public void SetMapValue(int value)
        {
            if (_ValuesMap.Contains(value))
            {
                ddlMap.SelectedIndex = _ValuesMap.IndexOf(value);
            }
            else
            {
                ddlMap.SelectedIndex = -1;
            }
        }

        public int GetSectionValue()
        {
            Int32 _returnValue = Int32.MinValue;
            try
            {
                if (ddlSection.Enabled && ddlSection.Items.Count > 0 && ddlSection.SelectedIndex > 0)
                {
                    _returnValue = _ValuesSection[ddlSection.SelectedIndex];
                }
            }
            catch (Exception ex)
            {
                _returnValue = Int32.MinValue;
            }
            return _returnValue;
        }

        public void SetSectionValue(int value)
        {
            if (_ValuesSection.Contains(value))
            {
                ddlSection.Enabled = true;
                ddlSection.SelectedIndex = _ValuesSection.IndexOf(value);
            }
            else
            {
                ddlSection.Enabled = false;
            }
        }

        public void Clean()
        {
            ddlMap.SelectedIndex = 0;
            ddlSection.SelectedIndex = 0;

        }
    }
}
